#include <string>
#include <iostream>
using namespace std;

class Solution
{
public:
	string addStrings(string num1, string num2)
	{
		int end1 = num1.size() - 1; int val1;
		int end2 = num2.size() - 1; int val2;
		int next = 0;
		string num3;
		while (end1 >= 0 || end2 >= 0)
		{
			if (end1 >= 0)
			{
				val1 = num1[end1--] - '0';
			}
			else val1 = 0;
			if (end2 >= 0)
			{
				val2 = num2[end2--] - '0';
			}
			else val2 = 0;
			int addret = val1 + val2 + next;
			if (addret > 9)
			{
				addret -= 10;
				next = 1;
			}
			num3 += (addret + '0');
		}
		if (next == 1)
		{
			num3 += '1';
		}
		reverse(num3.begin(), num3.end());
		return num3;
	}
};


//int main()
//{
//	Solution s;
//	cout << s.addStrings("111", "999") << endl;
//	return 0;
//}